package com.mairuide.exception_analysis.controller;

import com.mairuide._frame.base.BaseController;
import com.mairuide._frame.base.ModuleCode;
import com.mairuide._frame.utils.excel.ExcelExportUtil;
import com.mairuide.entity.PageResult;
import com.mairuide.entity.Result;
import com.mairuide.entity.StatusCode;
import com.mairuide.exception_analysis.pojo.ExceptionAnalysisDetail;
import com.mairuide.exception_analysis.pojo.ExceptionAnalysisDetail2;
import com.mairuide.exception_analysis.pojo.ExceptionAnalysisDetail3;
import com.mairuide.exception_analysis.pojo.ExceptionAnalysisVO;
import com.mairuide.exception_analysis.service.ExceptionAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @auther 刘中华
 * @create 2019-03-13 11:33
 */
@Controller
@RequestMapping("exception_analysis")
public class ExceptionAnalysisController extends BaseController {

    @Autowired
    ExceptionAnalysisService exceptionAnalysisService;

    @ModuleCode(pValue = "billskill", value = "exceptionAnalysis")
    @RequestMapping(method= RequestMethod.GET,value = "init")
    public Object init(ModelMap model){
        return "/methodsanalysis/exceptionAnalysis";
    }


    @RequestMapping("list/{page}/{size}")
    @ResponseBody
    public Result exception_analysis(@RequestBody Map<String,String> prop, @PathVariable int page, @PathVariable int size){
        String caseId = request.getSession().getAttribute("caseId") == null?"":request.getSession().getAttribute("caseId").toString();
        prop.put("casemanage_id",caseId);
        PageResult pageResult = exceptionAnalysisService.getlist(prop,page,size);
        return new Result(true, StatusCode.OK,"查询成功", pageResult);
    }
    @RequestMapping("list_easyui")
    @ResponseBody
    public PageResult exception_analysis_easyui(ExceptionAnalysisVO vo){
        PageResult pageResult = exceptionAnalysisService.getlist_easyui(vo);
        return pageResult;
    }
    @RequestMapping("shortTimeTransaction/{page}/{size}")
    @ResponseBody
    public Result shortTimeTransaction(@RequestBody Map<String,String> prop, @PathVariable int page, @PathVariable int size){
        String caseId = request.getSession().getAttribute("caseId") == null?"":request.getSession().getAttribute("caseId").toString();
        prop.put("casemanage_id",caseId);
        PageResult pageResult = exceptionAnalysisService.shortTimeTransaction(prop,page,size);
        return new Result(true, StatusCode.OK,"查询成功", pageResult);
    }
    @RequestMapping("shortTimeTransaction_easyui")
    @ResponseBody
    public PageResult shortTimeTransaction_easyui(ExceptionAnalysisVO vo){
        PageResult pageResult = exceptionAnalysisService.shortTimeTransaction_easyui(vo);
        return pageResult;
    }
    @RequestMapping("yinHangTransaction/{page}/{size}")
    @ResponseBody
    public Result yinHangTransaction(@RequestBody Map<String,String> prop, @PathVariable int page, @PathVariable int size){
        String caseId = request.getSession().getAttribute("caseId") == null?"":request.getSession().getAttribute("caseId").toString();
        prop.put("casemanage_id",caseId);
        PageResult pageResult = exceptionAnalysisService.yinHangTransaction(prop,page,size);
        return new Result(true, StatusCode.OK,"查询成功", pageResult);
    }
    @RequestMapping("yinHangTransaction_easyui")
    @ResponseBody
    public PageResult yinHangTransaction_easyui(ExceptionAnalysisVO vo){
        PageResult pageResult = exceptionAnalysisService.yinHangTransaction_easyui(vo);
        return pageResult;
    }
    @RequestMapping("postTransaction/{page}/{size}")
    @ResponseBody
    public Result postTransaction(@RequestBody Map<String,String> prop, @PathVariable int page, @PathVariable int size){
        String caseId = request.getSession().getAttribute("caseId") == null?"":request.getSession().getAttribute("caseId").toString();
        prop.put("casemanage_id",caseId);
        PageResult pageResult = exceptionAnalysisService.postTransaction(prop,page,size);
        return new Result(true, StatusCode.OK,"查询成功", pageResult);
    }
    @RequestMapping("postTransaction_easyui")
    @ResponseBody
    public PageResult postTransaction_easyui(ExceptionAnalysisVO vo){
        PageResult pageResult = exceptionAnalysisService.postTransaction_easyui(vo);
        return pageResult;
    }
    @RequestMapping(value = "down",method = RequestMethod.POST)
    public void exception_analysis_down(String interval_day,String count,String minTradeMoney,String maxTradeMoney,
                                        String minAccountMoney,String maxAccountMoney,String cardList,String beginTime,String endTime,String whichTab,String sign,String caseId
                                        ) throws Exception{
        HashMap<String, String> map = new HashMap<>();
        map.put("casemanage_id",caseId);
        map.put("count",count);
        map.put("sign",sign);
        map.put("interval_day",interval_day);
        map.put("minTradeMoney",minTradeMoney);
        map.put("maxTradeMoney",maxTradeMoney);
        map.put("minAccountMoney",minAccountMoney);
        map.put("maxAccountMoney",maxAccountMoney);
        map.put("beginTime",beginTime);
        map.put("endTime",endTime);
        map.put("cardList",cardList);
        PageResult getlist = null;
        Class clazz= ExceptionAnalysisDetail.class;
        //第一步 得到数据
        String name="异常资金分析.xlsx";
        if ("first".equals(whichTab)) {
            getlist = exceptionAnalysisService.getlist(map, 1, Integer.MAX_VALUE);
            name="规律交易.xlsx";
        }else if ("second".equals(whichTab)){
            getlist = exceptionAnalysisService.shortTimeTransaction(map, 1, Integer.MAX_VALUE);
            clazz= ExceptionAnalysisDetail2.class;
            name="短时间内的存款/取款.xlsx";
        }else if ("third".equals(whichTab)){
            getlist = exceptionAnalysisService.yinHangTransaction(map, 1, Integer.MAX_VALUE);
            clazz= ExceptionAnalysisDetail3.class;
            name="4~5w交易分析.xlsx";
        }else if ("fourth".equals(whichTab)){
            getlist = exceptionAnalysisService.postTransaction(map, 1, Integer.MAX_VALUE);
            clazz= ExceptionAnalysisDetail3.class;
            name="pos机消费分析.xlsx";
        }
        if (getlist!=null){
            List list = getlist.getRows();
            //第二步 下载excel
            new ExcelExportUtil(clazz).export(response,list,name);
        }
    }
}
